#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Local $binFile = FileOpenDialog("Select a binary file", @DesktopDir, "Binary (*.bin)")
if @error = 0 Then
	Run("D:\_sppkgr\CFC-1.0.9.exe")
	WinWaitActive("Compass Firmware Compressor")
	For $i = 1 To 2
		; 选择 CPU
		MouseClick("PRIMARY", 770, 365)
		MouseClick("PRIMARY", 770, 385)
		; 填写地址 0x80000
		MouseClick("PRIMARY", 1200, 365)
		Send("0x80000")
		; 打开源文件并加入
		MouseClick("PRIMARY", 1120, 395)
		WinWaitActive("打开")
		Send($binFile)
		Send("{ENTER}")
		WinWaitClose("打开")
		MouseClick("PRIMARY", 1200, 395)
		; 设置输出文件路径
		MouseClick("PRIMARY", 1200, 460)
		WinWaitActive("另存为")
		Send("D:\_sppkgr\update_boxed\OS.bin")
		Send("{ENTER}")
		WinWaitClose("另存为")
		; 压缩
		MouseClick("PRIMARY", 1120, 710)
		Sleep(1000)
	Next
	FileDelete("D:\_sppkgr\update_boxed\OS.bin" & ".aes.bin")
	FileDelete("D:\_sppkgr\update_boxed\OS.bin" & ".unaes.bin")
	FileDelete("D:\_sppkgr\update_boxed\OS.bin" & ".unzip.bin")
	FileDelete("D:\_sppkgr\update_boxed\OS.bin" & ".zip.bin")
	WinClose("Compass Firmware Compressor")
EndIf
